<?php
/**
* Set an image as a cover image
*/

#$albums = new albums();

/**
Array
(
	[page] => albums-coverimage.php
	[id] => 283
	[code] => ac9416901bef943a38b4b76b0d942d92
)
*/

$image_id = $variable->get('id', 'integer', 0); # Entity ID
$code = $variable->get('code', 'string', ''); # Protection Code

$images = new images();
$image = $images->details($image_id);
#print_r($image);
#print_r($_GET);

# album_coverimage
$album_id = $images->album_id($image_id);
$converimage_size_id=THUMBNAIL_COVERIMAGE_SIZE_ID;

# Also mark the particular image.
# Reset all old records of cover image
$coverimage_sqls = array();
$coverimage_sqls[]="UPDATE gallery_albums SET album_coverimage='{$converimage_size_id}/{$image_id}.jpg' WHERE album_id={$album_id};";
$coverimage_sqls[]="UPDATE gallery_images_albums SET is_coverimage='N' WHERE album_id={$album_id};";
$coverimage_sqls[]="UPDATE gallery_images_albums SET is_coverimage='Y' WHERE image_id={$image_id};";

foreach($coverimage_sqls as $ci => $coverimage_sql)
{
	$images->query($coverimage_sql);
}

stopper::url(url::last_page('images-list.php'));
#stopper::url('albums-list.php');
?>